﻿using System;
using System.Text;
using System.Web.Mvc;
using Sklep.WebUI.Models;

namespace Sklep.WebUI.HtmlHelpers
{
    public static class PaggingHelpers
    {
        public static MvcHtmlString PageLinks(this HtmlHelper html, 
                                              PagingInfo info, 
                                              Func<int,string> pageUrl)
        {
            var result = new StringBuilder();
            for (int i = 1; i <= info.TotalPages; i++)
            {
                var tag = new TagBuilder("a");   //tworzenie znacznika <a>
                tag.MergeAttribute("href",pageUrl(i));
                tag.InnerHtml = i.ToString();
                if(i == info.CurrentPage)
                    tag.AddCssClass("selected");
                result.Append(tag.ToString());
            }

            return MvcHtmlString.Create(result.ToString());
        }
    }
}